package com.tjetc.service.impl;

import com.tjetc.dao.AnimalMapper;
import com.tjetc.dao.ParkAnimalMapper;
import com.tjetc.dao.ParkMapper;
import com.tjetc.domain.Animal;
import com.tjetc.domain.Park;
import com.tjetc.domain.ParkAnimal;
import com.tjetc.service.ParkAnimalService;
import com.tjetc.service.ParkService;
import com.tjetc.utils.Db;
import com.tjetc.vo.Result;

public class ParkAnimalServiceImpl implements ParkAnimalService {
    private ParkAnimalMapper parkAnimalMapper= Db.getMapper(ParkAnimalMapper.class);
    private AnimalMapper animalMapper=Db.getMapper(AnimalMapper.class);
    private ParkMapper parkMapper=Db.getMapper(ParkMapper.class);
    @Override
    public Result insert(ParkAnimal parkAnimal) {
        Animal animal=animalMapper.getById(parkAnimal.getAnimalId());
        if (animal==null){
            return new Result(500,"动物不存在",null);
        }
        Park park=parkMapper.getById(parkAnimal.getParkId());
        if (park==null){
            return new Result(500,"园区不存在",null);
        }
        int rows=parkAnimalMapper.insert(parkAnimal);
        if (rows==1){
            return new Result(200,"添加成功",null);
        }
        return new Result(500,"添加失败",null);
    }

    @Override
    public Result update(ParkAnimal parkAnimal) {

        Animal animal=animalMapper.getById(parkAnimal.getAnimalId());
        if (animal==null){
            return new Result(500,"动物不存在",null);
        }
        ParkAnimal parkAnimal1=parkAnimalMapper.getByAnimalId(parkAnimal.getAnimalId());
        if (parkAnimal1==null){
            return new Result(500,"该动物没分配呢啊",null);
        }
        Park park=parkMapper.getById(parkAnimal.getParkId());
        if (park==null){
            return new Result(500,"园区不存在",null);
        }
        int rows=parkAnimalMapper.update(parkAnimal);
        if (rows==1){
            return new Result(200,"修改成功",null);
        }
        return new Result(500,"修改失败",null);
    }
}
